package com.lcj.dr.controller;

import com.github.pagehelper.PageInfo;
import com.lcj.common.util.Result;
import com.lcj.dr.controller.form.CanPayForm;
import com.lcj.dr.controller.form.PayFineForm;
import com.lcj.dr.controller.form.SearchFineForm;
import com.lcj.dr.db.pojo.DriverFineEntity;
import com.lcj.dr.service.FineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;

@RestController
@RequestMapping("/fine")
@Tag(name = "FineController", description = "罚款接口")
public class FineController {

    @Resource
    private FineService fineService;

    @PostMapping("/searchFineByPage")
    @Operation(description = "分页查询罚款列表")
    public Result searchFineByPage(@RequestBody @Valid SearchFineForm form) {
        PageInfo<DriverFineEntity> result = fineService.searchFineByPage(form);
        return Result.ok().put("result", result);
    }

    @PostMapping("/canPay")
    @Operation(description = "判断是否能支付")
    public Result canPay(@RequestBody @Valid CanPayForm form) {
        HashMap result = fineService.canPay(form);
        return Result.ok().put("result", result);
    }

    @PostMapping("/payFine")
    @Operation(description = "支付罚款")
    public Result payFine(@RequestBody @Valid PayFineForm form) {
        Integer result = fineService.payFine(form);
        return Result.ok().put("rows", result);
    }

}
